package com.cdtu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdtu.comon.BaseContext;
import com.cdtu.entity.Admin;
import com.cdtu.service.AdminService;
import com.cdtu.mapper.AdminMapper;
import com.cdtu.vo.R;
import org.apache.ibatis.annotations.One;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
* @author wp
* @description 针对表【admin】的数据库操作Service实现
* @createDate 2023-01-10 19:53:57
*/
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin>
    implements AdminService{

    @Override
    public R getLogin(String username, String password) {
        LambdaQueryWrapper<Admin> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Admin::getUsername,username).eq(Admin::getPassword,password);
        Admin admin = getOne(queryWrapper);
        if (admin!=null){
            if (admin.getState()==1) {
                //登录成功将登录的管理员存入到当前线程中
                BaseContext.setCurrentAdmin(admin);
                return R.success(admin);
            } else {
                return R.error("该账号被禁用");
            }
        }
        return R.error("账号或密码错误！");
    }
}




